package com.spring.demo.untils.parse.blood;

import com.spring.demo.untils.dto.HisBloodBagStatusRequest;
import com.spring.demo.untils.dto.OpenRes;
import com.spring.demo.untils.dto.Result;
import com.spring.demo.untils.parse.ResponseParse;

import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * @author xuweizhi
 * @since 2023/07/06 17:46
 */
public class BloodOperateOrderResponseParse implements ResponseParse<HisBloodBagStatusRequest> {


    @Override
    public boolean matchParse(String suffixUrl, Long routerId) {
        return Objects.equals(suffixUrl, "/gw-api/hbos-thirdparty-integration/standard/bimis/nurse/bloodBagStatusSync") ;
    }

    @Override
    public HisBloodBagStatusRequest parseRequestBody(OpenRes openRes) {
        Result<String> resResult = this.parseResponseBody(openRes);
        // if (!Objects.equals(resResult.getCode(), 200)) {
        //     return null;
        // }
        OpenRes.OriginRequestDTO originRequest = openRes.getOriginRequest();
        return GSON.fromJson(originRequest.getBody(), HisBloodBagStatusRequest.class);
    }

    @Override
    public void execute(List<HisBloodBagStatusRequest> data) {

        List<HisBloodBagStatusRequest> collect = data.stream().filter(hisBloodBagStatusRequest -> Objects.equals(hisBloodBagStatusRequest.getOperationType(), 202)).collect(Collectors.toList());
        collect.forEach(x -> x.getBloodBagInfoList().forEach(hisSimpleBloodInfoDTO -> System.out.println(hisSimpleBloodInfoDTO.getBloodBagNo() + "," + x.getOperateTime())));
    }


}
